package C;

import java.util.LinkedList;
import java.util.Scanner;

public class C8My {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(getResult(s));
    }

    public static int getResult(String s) {
        int count = 0;
        LinkedList<Character> stack = new LinkedList<>();
        for (int i=0;i<s.length();i++) {
            char c = s.charAt(i);
            if (c != '(' && c!= ')') {
                continue;
            } else if(c == '(') {
                stack.add(c);
            } else if(c == ')') {
                if (stack.size()==0) {
                    return -1;
                }
                if (stack.pop() == '(') {
                    count++;
                } else {
                    return -1;
                }

            }
        }
        return stack.size()==0?count:-1;
    }
}
